﻿<script src="../Scripts/shared/share.js" type="text/javascript"></script> 
<link rel="stylesheet" href="../Scripts/kindeditor-4.1.10/themes/default/default.css" />
<script charset="utf-8" src="../Scripts/kindeditor-4.1.10/kindeditor-all.js"></script>
<script charset="utf-8" src="../Scripts/kindeditor-4.1.10/lang/zh_CN.js"></script>  
<style>
    .tabs-container {
        display: flex;
        justify-content: left;
    }
    .tab-button {
        padding: 0 7px;
        background-color: #f0f0f0;
        border: 1px solid #ccc;
        cursor: pointer;
        text-decoration: none;        
        border-radius: 3px;
        margin-right:4px;
    }
    .active-tab-button {
        background-color: #41B2DF;
        border-color: #EDAC2F;
        color:#fff;
        border-radius: 5px;
    }
    .tab-content {
        display: none;
        margin-top: 20px;
    }
    .tab-content.active {
        display: block;
    }
</style>  
<form id="form1" method="post" style="height:92%;">
        <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
            <table style="width:100%;">
                <tr>
                    <td style="width:100%;">
                        <a class="mini-button" name="SaveInfo" iconCls="icon-save" onclick="onSaveInfo" plain="true">保存</a>
                        <a class="mini-button" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
                    </td>
                </tr>
            </table>                
        </div>    
    <div id="tabs1" class="mini-tabs" activeIndex="0"  style="width:100%; height:100%; top: 0px; left: 0px;overflow:hidden;border:none;" plain="true"  
        buttons="#tabsButtons" onactivechanged="changeTabs">
        <div name="Base" title="基本资料" style="height:100%;overflow:hidden;">
           <div title="基本信息(*必填)(带条码为普通产品称重为生鲜产品计件为称重按个卖产品)" class="mini-panel" style="width:100%;height:210px;" buttons="">
                 <table style="width:100%;margin-top:2px;">
                    <tr>
                        <td width="80px" height ="29px" align="right"><span style="color:red;">*</span>商品类型：</td>
                        <td width="200px" height ="29px">
                            <div class="tabs-container">
                                <a class="tab-button" data-tab="0">普通商品</a>
                                <a class="tab-button" data-tab="1">生鲜商品</a>
                                <a class="tab-button" data-tab="2">计件商品</a>
                            </div>                            
                        </td>
                        <td width="80px" height ="29px" align="right">称重PLU：</td>
                        <td width="200px" height ="29px"> 
                            <input id="FWeighPlu" name="FWeighPlu" class="mini-spinner" changeOnMousewheel="false" minValue="0" maxValue="99999"
                            style="width:200px;" TabIndex="0" showbutton="false" allowNull="true" onvaluechanged="GetGoodWeighPlu" />                         
                        </td>                        
                    </tr>
                    <tr>
                        <td width="80px" height ="29px" align="right">商品编码：</td>
                        <td width="200px" height ="29px">
                            <input name="FNumber" id="FNumber" class="mini-textbox" style="width:200px;" maxlength="50" value="" TabIndex="1"/>                        
                        </td>
                        <td width="80px" height ="29px" align="right"><span style="color:red;">* </span>单位：</td>
                        <td width="200px" height ="29px">
                            <input id="FUnitName" name="FUnitName" class="mini-combobox" style="width:200px;" textField="FUnitName" valueField="FUnitName"
                                showNullItem="false" allowInput="true" TabIndex="4"/>
                        </td>
                    </tr>
                    <tr>
                        <td width="80px" height ="29px" align="right"><span style="color:red;">* </span>商品条码：</td>
                        <td width="200px" height ="29px">
                            <input id="FCode" name="FCode" class="mini-textbox " onvaluechanged="FindGood" maxlength="50"  style="width:200px;" TabIndex="2"/>                        
                        </td>
                        <td width="80px" height ="29px" align="right">零售价：</td>
                        <td width="200px" height ="29px">
                            <input id="FPosPrice" name="FPosPrice" class="mini-spinner" changeOnMousewheel ="false"  minValue="0"  maxValue="9999999"
                                style="width:200px;" TabIndex="5"  showbutton="false" allowNull="true" onkeydown="ComputeGPM" onblur="ComputeGPM" 
                                format="#.00"/> 
                        </td>
                    </tr>
                    <tr>
                        <td width="80px" height ="29px" align="right"><span style="color:red;">* </span>商品名称：</td>
                        <td width="200px" height ="29px">
                            <input id="FName" name="FName" class="mini-textbox "  style="width:200px;" maxlength="100" TabIndex="3"/>                                                  
                        </td>
                        <td width="80px" height ="29px" align="right">进货价：</td>
                        <td width="200px" height ="29px">
                            <input id="FPurPrice" name="FPurPrice" class="mini-spinner" changeOnMousewheel ="false" minValue="0"  maxValue="9999999"
                                    style="width: 116px;" TabIndex="6" showbutton="false" allowNull="true" onkeydown="ComputeGPM" onblur="ComputeGPM"/>
                            <input id="FGPM" name="FGPM" class="mini-spinner" changeOnMousewheel="false" minValue="0" maxValue="100" align="left"
                                   style="width: 80px;" TabIndex="7" showbutton="false" allowNull="true"  format="#,0.00" increment ="0.01" 
                                   onkeydown="ComputePrice" onblur="ComputePrice"/>
                        </td>
                    </tr>
                    <tr>
                        <td width="80px" height ="29px" align="right">商品分类：</td>
                        <td width="200px" height ="29px">
                            @Html.Partial("~/Views/Modular/LookupGoodsClassSelf.cshtml")
                        </td>
                        <td width="80px" height ="29px" align="right">会员价：</td>
                        <td width="200px" height ="29px">
                            <input name="FVipPrice" class="mini-spinner" changeOnMousewheel ="false"  minValue="0"  maxValue="9999999"
                                style="width:200px;" TabIndex="7" showbutton="false" format="#,0.00" allowNull="true"/>                
                        </td>
                    </tr>
                </table>           
            </div>

            <div title="其它信息(选填)" class="mini-panel" style="width:100%;height:230px;" buttons="">
                <table style="width:100%;margin-top:0px;">
                    <tr>
                        <td width="80px" height="29px" align="right">规格型号：</td>
                        <td width="200px" height="29px">
                            <input id="FSpec" name="FSpec" class="mini-textbox " maxlength="50" style="width:200px;" TabIndex="9" />
                        </td>
                        <td width="80px" height ="29px" align="right">配送价：</td>
                        <td width="200px" height ="29px">
                            <input id="FRmoPrice" name="FRmoPrice" class="mini-spinner"changeOnMousewheel ="false"  
                             minValue="0"  maxValue="9999999" style="width:200px;" TabIndex="8" showbutton="false" allowNull="true"/>
                        </td>
                    </tr>
                    <tr>
                        <td width="80px" height="29px" align="right">主供应商：</td>
                        <td width="200px" height="29px">
                            @Html.Partial("~/Views/Modular/LookUpSupply.cshtml")
                        </td>
                        <td width="80px" height="29px" align="right">批发价：</td>
                        <td width="200px" height="29px">
                            <input id="FSelPrice" name="FSelPrice" class="mini-spinner" changeOnMousewheel="false" minValue="0" maxValue="9999999"
                                   style="width:200px;" TabIndex="13" showbutton="false" format="#,0.00" allowNull="true" />
                        </td>
                    </tr>
                    <tr>
                        <td width="80px" height="23px" align="right">组织机构：</td>
                        <td width="200px" height="23px">
                            @Html.Partial("~/Views/Modular/LookupPriceBook.cshtml")
                        </td>
                        <td width="80px" height="29px" align="right">电商价：</td>
                        <td width="200px" height="29px">
                            <input id="FMallPrice" name="FMallPrice" class="mini-spinner" changeOnMousewheel="false" minValue="0" maxValue="9999999"
                                    style="width:70px;" TabIndex="14" showbutton="false" format="#,0.00" allowNull="true" />+
                            <input id="FMallPoint" name="FMallPoint" class="mini-spinner" changeOnMousewheel="false" minValue="0" maxValue="9999999"
                                    style="width:70px;" TabIndex="15" showbutton="false" allowNull="true" />积分兑换
                        </td>
                    </tr>
                    <tr>
                        <td width="80px" height="29px" align="right">当前库存：</td>
                        <td width="200px" height="29px">
                            <input id="FStockTotal" name="FStockTotal" class="mini-spinner " maxlength="50" style="width:200px;" minValue="-999999"
                             maxValue="9999999" TabIndex="11" showbutton="false" allowNull="true" changeOnMousewheel="false" format="n" />
                        </td>
                        <td width="80px" height="23px" align="right">提成系数：</td>
                        <td width="200px" height="23px">
                            <input name="FRebateAmt" class="mini-spinner" minValue="0" maxValue="99999999" changeOnMousewheel="false" value="0"
                                   style="width: 70px;" TabIndex="1013" showbutton="false" format="#,0.00" align="right" selectOnFocus="true" />
                            <input id="FRebateID" name="FRebateID" class="mini-combobox" style="width:125px;margin-left:0px;" showNullItem="false"
                                   allowInput="false" align="left" value="0" data="comPoolAgio" />
                        </td>
                    </tr>
                     <tr>
                        <td width="80px" height="23px" align="right">最低折扣：</td>
                        <td width="200px" height="23px">
                            <input name="FLowestDis" class="mini-spinner" minValue="0" maxValue="1" changeOnMousewheel="false"
                            style="width:60px;" TabIndex="1002" showbutton="false" allowNull="true" />
                            <a class="mini-button" style="width:64px;" name="noDiscount" onclick="SetDiscount(0)">任意打折</a>
                            <a class="mini-button" style="width:64px;" name="noDiscount" onclick="SetDiscount(1)">不可打折</a>                            
                        </td>
                        <td width="80px" height="23px" align="right">会员积分：</td>
                        <td width="200px" height="23px">
                            <input id="FPoint" name="FPoint" class="mini-spinner " style="width:70px;" minValue="-1" maxValue="99999999" TabIndex="16"
                                   showbutton="false" allowNull="true" />
                            <input id="FPointType" name="FPointType" class="mini-combobox" style="width:125px;margin-left:0px;" showNullItem="false"
                                   allowInput="false" align="left" value="0" data="comPointType" />
                        </td>
                    </tr>
                     <tr>
                        <td width="80px" height="20px" align="right">提示：</td>
                        <td width="200px" height="20px">
                           1表示不可打折，0.9表示最低可打9折
                        </td>
                        <td width="80px" height="20px" align="right">提示：</td>
                        <td width="200px" height="20px">-1表示不参与所有积分规则</td>
                    </tr>
                </table> 
            </div>
        </div>
        <div id="More" name="More" title="其它资料" style="height:100%;overflow:hidden;">
            <table id="OtherTable" name="OtherTable" style="width:100%;margin-top:10px;">
                <tr>
                    <td width="80px" height="30px" align="right">商品品牌：</td>
                    <td width="200px" height="30px">
                        @Html.Partial("~/Views/Modular/LookupGoodsBrand.cshtml")
                    </td>
                    <td width="80px" height="30px" align="right">商品重量：</td>
                    <td width="200px" height="30px">
                        <input id="FWeight" name="FWeight" class="mini-spinner" style="width:200px;" TabIndex="1001" />
                    </td>
                </tr>
                <tr>
                    <td width="80px" height="30px" align="right">生产日期：</td>
                    <td width="200px" height="30px">
                        <input id="FMadeDate" name="FMadeDate" class="mini-datepicker " format="yyyy-MM-dd" style="width:200px;" tabindex="1004" />
                    </td>
                    <td width="80px" height="30px" align="right">
                        &nbsp;保&nbsp;质&nbsp;期：
                    </td>
                    <td width="200px" height="30px">
                        <input id="FQuality" name="FQuality" class="mini-textbox " style="width:200px;" TabIndex="1003" />
                    </td>
                </tr>
                <tr>
                    <td width="80px" height="30px" align="right">保质期：</td>
                    <td width="200px" height="30px">
                        <input id="FLife" name="FLife" class="mini-spinner" changeOnMousewheel="false" minValue="0" maxValue="9999999"
                               style="width:200px;" TabIndex="1006" showbutton="false" allowNull="true" /><span> 天</span>
                    </td>
                    <td width="80px" height="30px" align="right">商品体积：</td>
                    <td width="200px" height="30px">
                        <input id="FBulk" name="FBulk" class="mini-spinner " style="width:200px;" TabIndex="1005" />
                    </td>
                </tr>
                <tr>
                    <td width="80px" height="30px" align="right">商品属性：</td>
                    <td width="200px" height="30px">
                        <input id="FAttribute" name="FAttribute" class="mini-textbox " maxlength="50" style="width:200px;" TabIndex="1008" />
                    </td>
                    <td width="80px" height="30px" align="right">商品产地：</td>
                    <td width="200px" height="30px">
                        <input id="FHome" name="FHome" class="mini-textbox " style="width:200px;" TabIndex="1007" />
                    </td>
                </tr>
                <tr>
                    <td width="80px" height="30px" align="right">库存下限：</td>
                    <td width="200px" height="30px">
                        <input id="FLowLimit" name="FLowLimit" class="mini-spinner" changeOnMousewheel="false" minValue="0" maxValue="9999999"
                               style="width:200px;" TabIndex="1012" showbutton="false" allowNull="true" />
                    </td>
                    <td width="80px" height="30px" align="right">代理返利：</td>
                    <td width="200px" height="30px">
                        <input name="FRebate1" class="mini-spinner" minValue="0" maxValue="99999999" changeOnMousewheel="false" value="0"
                               required="true" style="width: 200px;" TabIndex="1009" showbutton="false" format="#,0.00" align="right" />
                    </td>
                </tr>
                <tr>
                    <td width="80px" height="30px" align="right">库存上限：</td>
                    <td width="200px" height="30px">
                        <input id="FHightLimit" name="FHightLimit" class="mini-spinner" changeOnMousewheel="false" minValue="0" maxValue="9999999"
                               style="width:200px;" TabIndex="1010" showbutton="false" allowNull="true" />
                    </td>
                    <td width="80px" height="30px" align="right">商铺返利：</td>
                    <td width="200px" height="30px">
                        <input name="FRebate2" class="mini-spinner" minValue="0" maxValue="99999999" changeOnMousewheel="false" value="0"
                               required="true" style="width: 200px;" TabIndex="1011" showbutton="false" format="#,0.00" align="right" />
                    </td>
                </tr>
                <tr>
                    <td width="80px" height="30px" align="right">商品类型：</td>
                    <td width="200px" height="30px">
                        <input id="FPackFlag" name="FPackFlag" class="mini-combobox" style="width:200px;" showNullItem="false"
                               allowInput="false" align="left" value="0" data="comPackFlag" />
                    </td>
                    <td width="80px" height="30px" align="right">助记码：</td>
                    <td width="200px" height="30px">
                        <input id="FSpelling" name="FSpelling" class="mini-textbox " style="width:100px;" Enabled="false" TabIndex="1014" />
                        <div id="FSpellingType" name="FSpellingType" class="mini-checkbox" style="margin-right: 20px" readOnly="false" 
                        checked="false" text="自定义助记码" onvaluechanged="SpellingCheck"></div>                        
                    </td>
                </tr>
                <tr>
                    <td width="80px" height="30px" align="right">商品状态：</td>
                    <td width="200px" height="30px">
                        <input id="FDeleted" name="FDeleted" class="mini-combobox" style="width:200px;" showNullItem="false"
                               allowInput="false" align="left" value="1" data="comPriceType" />
                    </td>
                    <td width="80px" height="30px" align="right">生产许可证:</td>
                    <td width="200px" height="30px">
                        <input id="FQSNumber" name="FQSNumber" class="mini-textbox " maxlength="100" style="width:200px;" TabIndex="1015" />
                    </td> 
                </tr>
                <tr>
                    <td width="80px" height="30px" align="right">是否上架：</td>
                    <td width="200px" height="30px">
                        <input id="FMallFlag" name="FMallFlag" class="mini-combobox" style="width:200px;" showNullItem="false"
                               allowInput="false" align="left" value="1" data="comFlag" tabindex="12" />
                    </td>
                    <td width="80px" height="30px" align="right">可否要货：</td>
                    <td width="200px" height="30px">
                        <input id="FRequireFlag" name="FRequireFlag" class="mini-combobox" style="width:200px;" showNullItem="false"
                               allowInput="false" align="left" value="1" data="comFlag" tabindex="16" />
                    </td>
                </tr>
                <tr>
                    <td width="80px" height="30px" align="right">电商单位：</td>
                    <td width="200px" height="30px">
                        <input id="FMallUnit" name="FMallUnit" class="mini-textbox " style="width:200px;" TabIndex="4"/>
                    </td>
                    <td width="80px" height ="30px" align="right">电商内装数：</td>
                    <td width="200px" height ="30px">
                         <input id="FMallConvert" name="FMallConvert" class="mini-spinner" changeOnMousewheel ="false" minValue="0"  maxValue="9999999"
                         style="width: 200px;" TabIndex="6" format="#,0.00" value="1" showbutton="false" allowNull="true"/>  
                    </td>
                </tr>
                <tr>
                    <td width="80px" height ="30px" align="right">电商热销：</td>
                    <td width="200px" height ="30px">
                        <input id="FHotSale" name="FHotSale" class="mini-combobox" style="width:200px;" showNullItem="false"
                         allowInput="false" align="left" value="1" data="comFlag" tabindex="12" />
                    </td>
                    <td width="80px" height="30px" align="right">计量方式：</td>
                    <td width="200px" height="30px">
                        <input id="FPriceType" name="FPriceType" class="mini-combobox" style="width:200px;" showNullItem="false"
                                allowInput="false" align="left" value="0" data="comState"  onvaluechanged="onPriceTypeChanged()"/>
                    </td>                    
                </tr>
            </table>
        </div>
        <div id="Other" name="Other" title="其它设置" style="height:100%;overflow:hidden;">
           <table id="OtherTable" name="OtherTable" style="width:100%;margin-top:10px">
                <tr>
                    <td width="80px" height ="30px" align="right"></td>
                    <td width="200px" height ="30px">
                        <div id="FStockLimitFlag" name="FStockLimitFlag" class="mini-checkbox" style="margin-right: 20px" readOnly="false" 
                        checked="false" text="库存预警" onvaluechanged="limitCheck"></div>
                    </td>
                   <td width="80px" height ="30px" align="right"></td>
                   <td width="200px" height ="30px">                        
                   </td>
                </tr>
                <tr>
                     <td width="80px" height ="30px" align="right"></td>
                    <td width="200px" height ="30px">      
                        <div id="ck2" name="ck2"  class="mini-checkbox" style ="margin-right:20px" readOnly="false" value ="false" text="颜色尺码" onvaluechanged="ck2Select"></div>                  
                    </td>
                    <td width="80px" height ="30px" align="right"></td>
                    <td width="200px" height ="30px">
                        
                    </td>
                </tr>
               <tr class="rebateRow" style="display: none;">
                   <td width="80px" height="30px" align="right"></td>
                   <td width="200px" height="30px">
                       @*<div id="FMallFlag" name="FMallFlag" class="mini-checkbox" style="margin-right: 20px" readOnly="false" checked="true" text="是否上架(商城) "></div>*@
                   </td>
                   <td width="80px" height="30px" align="right"></td>
                   <td width="200px" height="30px">
                   </td>
               </tr>
                <tr>
                    <td width="80px" height ="30px" align="right"></td>
                    <td width="200px" height ="30px">商品二维码：                        
                    </td>
                    <td width="80px" height="30px" align="right"></td>
                </tr>
                <tr>
                    <td width="80px" height="30px" align="right"></td>
                    <td width="200px" height="30px" rowspan="6">
                        <iframe src="" id="QCodeIFrame" width="190px" height="190px" frameborder=0 marginheight=0 marginwidth=0 scrolling=no></iframe>
                    </td>
                    <td width="80px" height ="30px" align="right" style="vertical-align:top;padding-top:5px;"></td>
                    <td width="200px" height ="30px" style="vertical-align:top;padding:0;">
                    </td>
                </tr>
                <tr>
                    <td width="80px" height ="30px" align="right"></td>
                    <td width="200px" height ="30px">
                        
                    </td>
                    <td width="80px" height="30px" align="right"></td>
                </tr>
                <tr>
                    <td width="80px" height ="30px" align="right"></td>
                    <td width="200px" height ="30px" >
                    </td>
                    <td width="80px" height="30px" align="right"></td>
                </tr>
                <tr>
                    <td width="80px" height ="30px" align="right"></td>
                    <td width="200px" height ="30px" >
                    </td>
                    <td width="80px" height="30px" align="right"></td>
                </tr>
                <tr>
                    <td width="80px" height ="30px" align="right"></td>
                    <td width="200px" height ="30px" >
                    </td>
                    <td width="80px" height="30px" align="right"></td>
                </tr>
                <tr>
                    <td width="80px" height ="30px" align="right"></td>
                    <td width="200px" height ="30px" >
                    </td>
                    <td width="80px" height="30px" align="right"></td>
                </tr>
            </table>
        </div>
        <div name="Spec" title="包装规格" style="height:110%;overflow:hidden;">
            @Html.Partial("~/Views/Modular/GoodEditBar.cshtml")
            <div id="Specgrid" class="mini-datagrid" style="width:100%;height:90%;" pageSize="15"
                    borderStyle="border:1;" url="GetGoodsSpecs" showPager="false" idField="FItemID"
                    allowCellSelect="true" allowCellEdit="true"showColumnsMenu="true"fitColumns="false"  
                    sortMode="client">
                <div property="columns">
                    <div type="checkcolumn" >选行</div>
                    <div header="FItemID" field="FItemID" width="0" visible="false"></div>
                    <div field="FCode" name="FCode" width="120" headeralign="center" allowsort="true">商品条码
                        <input property="editor" class="mini-textbox PopInput" style="width:100%;"/>
                    </div>
                    <div field="FAttribute" name="FAttribute" width="100" headeralign="center" allowsort="true">商品属性
                        <input property="editor" class="mini-textbox PopInput" style="width:100%;"/>
                    </div>
                    <div field="FSpec" name="FSpec" width="100" headeralign="center" allowsort="true">规格
                        <input property="editor" class="mini-textbox PopInput" style="width:100%;"/>
                    </div>
                    <div field="FUnitName" name="FUnitName" width="40" headeralign="center" allowsort="true">单位
                        <input property="editor" class="mini-textbox PopInput" style="width:100%;"/>
                    </div>
                    <div field="FConvert" name="FConvert" width="60" headeralign="center" allowsort="true">内装数
                        <input property="editor" class="mini-textbox PopInput" style="width:100%;"/>
                    </div>
                    <div field="FPurPrice" name="FPurPrice" width="70" numberFormat="#,0.00" headerAlign="center" align="right" allowSort="true">进货价
                        <input property="editor" class="mini-spinner PopInput" minValue="0" maxValue="99999999" value="0" style="width:100%;"/>
                    </div>
                    <div field="FPosPrice" name="FPosPrice" width="70" numberFormat="#,0.00" headerAlign="center" align="right" allowSort="true">零售价
                        <input property="editor" class="mini-spinner PopInput" minValue="0" maxValue="99999999" value="0" style="width:100%;"/>
                    </div>
                    <div field="FRmoPrice" name="FRmoPrice" width="70" numberFormat="#,0.00" headerAlign="center" align="right" allowSort="true">配送价
                        <input property="editor" class="mini-spinner PopInput" minValue="0" maxValue="99999999" value="0" style="width:100%;"/>
                    </div>
                    <div field="FSelPrice" name="FSelPrice" width="70" numberFormat="#,0.00" headerAlign="center" align="right" allowSort="true">批发价
                        <input property="editor" class="mini-spinner PopInput" minValue="0" maxValue="99999999" value="0" style="width:100%;"/>
                    </div>
                    <div field="FVipPrice" name="FVipPrice" width="70" numberFormat="#,0.00" headerAlign="center" align="right" allowSort="true">会员价
                        <input property="editor" class="mini-spinner PopInput" minValue="0" maxValue="99999999" value="0" style="width:100%;"/>
                    </div>
                    <div field="FMallPrice" name="FMallPrice" width="70" numberFormat="#,0.00" headerAlign="center" align="right" allowSort="true">电商价
                        <input property="editor" class="mini-spinner PopInput" minValue="0" maxValue="99999999" value="0" style="width:100%;"/>
                    </div>
                    <div field="FMallConvert" name="FMallConvert" width="80" numberFormat="#,0.00" headerAlign="center" align="right" allowSort="true">电商内装数
                        <input property="editor" class="mini-spinner PopInput" minValue="0" maxValue="99999999" value="0" style="width:100%;"/>
                    </div>
                    <div field="FMallUnit" name="FMallUnit" width="60" headeralign="center" allowsort="true">电商单位
                        <input property="editor" class="mini-textbox PopInput" style="width:100%;"/>
                    </div>
                    <div field="FLowestDis" name="FLowestDis" width="70" numberFormat="#,0.00" headerAlign="center" align="right" allowSort="true">最低折扣
                        <input property="editor" class="mini-spinner PopInput" minValue="0" maxValue="1" value="1" style="width:100%;"/>
                    </div>
                    <div field="FMallFlag" type="checkboxcolumn" name="FMallFlag" trueValue="1" falseValue="0" width="60" headeralign="center" allowsort="true">是否上架</div>
                    <div field="FRequireFlag" type="checkboxcolumn" name="FRequireFlag" trueValue="1" falseValue="0" width="60" headeralign="center" allowsort="true">可否要货</div>
                </div>
            </div>
        </div>
        <div name="DPic" id="DPic" title="展示图片" style="height:100%;overflow:hidden;">
            <table style= "width:100%; height:89%;">
                <tr>
                    <td class="auto-style1" colspan="10">
                        <div id="div_imglist" style="margin-left:30px;">
                                <img id="Image0" src="~/Content/Images/NoImage.jpg" Width="120" height="120" /> 
                                <img id="Image1" src="~/Content/Images/NoImage.jpg" Width="120" height="120" /> 
                                <img id="Image2" src="~/Content/Images/NoImage.jpg" Width="120" height="120" /> 
                                <img id="Image3" src="~/Content/Images/NoImage.jpg" Width="120" height="120" /> 
                                <img id="Image4" src="~/Content/Images/NoImage.jpg" Width="120" height="120" />
                        </div>
                    </td>            
                </tr>                
                <tr>
                    <td class="auto-style1" colspan="10">
                        <div id="div_imglist1" style="margin-left:30px;">
                                <img id="Image5" src="~/Content/Images/NoImage.jpg" Width="120" height="120" /> 
                                <img id="Image6" src="~/Content/Images/NoImage.jpg" Width="120" height="120" /> 
                                <img id="Image7" src="~/Content/Images/NoImage.jpg" Width="120" height="120" /> 
                                <img id="Image8" src="~/Content/Images/NoImage.jpg" Width="120" height="120" /> 
                                <img id="Image9" src="~/Content/Images/NoImage.jpg" Width="120" height="120" />
                        </div>
                    </td>
                </tr>
                <tr>
                    <td style="padding-left:30px;" colspan="10">
                        <input class="mini-button" text="按条码自动匹配所有商品图" onclick="syncImage" />
                        <!--<input class="mini-button" text="从图库查找导入商品图" onclick="getGoodsImgFrom" />
                        <input class="mini-button" text="获取所有商品图" onclick="syncAllImage" />-->
                    </td>
                </tr>
            </table>
        </div>
        <div id="DHtml" name="DHtml" title="商城详情" style="height:100%;overflow:hidden;">
            <textarea id="content" name="content" style="width:700px;height:400px;visibility:hidden;"></textarea>
        </div>

        <div name="Price" title="价格方案" style="height:110%;overflow:hidden;">            
            <div id="price_grid" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"  borderStyle="border:1;" url="" 
                    allowCellSelect="true" allowCellEdit="true" showColumnsMenu="true" fitColumns="false" skipReadOnlyCell="true" 
                    multiSelect="true" editNextOnEnterKey="true"  editNextRowCell="false" allowCellEdit="true" navEditMode="true">
                <div property="columns">
                    <div field="FBookName" name="FBookName" width="100" headeralign="center" allowsort="true">方案名称</div>
                    <div field="FCode" name="FCode" width="110" headeralign="center" allowsort="true">商品条码</div>
                    <div field="FName" name="FName" width="150" headeralign="center" allowsort="true">商品名称</div>
                    <div field="FSpec" name="FSpec" width="90" headeralign="center" allowsort="true">规格型号</div>
                    <div field="FUnitName" name="FUnitName" width="40" headeralign="center" allowsort="true">单位</div>
                    <div field="FRmoPrice" name="FRmoPrice" width="80" numberFormat="#,0.00" headerAlign="center" align="right" allowSort="true">配送价
                        <input property="editor" class="mini-spinner" maxValue="99999999" style="width:100%;"changeOnMousewheel ="false" showbutton="false" increment ="0" />
                    </div>
                    <div field="FSelPrice" name="FSelPrice" width="80" numberFormat="#,0.00" headerAlign="center" align="right" allowSort="true">批发价
                        <input property="editor" class="mini-spinner" maxValue="99999999" style="width:100%;"changeOnMousewheel ="false" showbutton="false" increment ="0" />
                    </div>
                    <div field="FConvert" name="FConvert" width="70" headeralign="center" allowsort="true">内装数</div>
                    <div field="FNumber" name="FNumber" width="100" headeralign="center" allowsort="true">商品编码</div>
                    <div field="FBookNumber" name="FBookNumber" width="100" headeralign="center" allowsort="true">价格方案编码</div>                    
                </div>
            </div>
        </div>

        <div name="colorSpec" title="颜色尺码" style="height:100%;overflow:hidden;">
            <div id="subtabs1" class="mini-tabs" activeIndex="0"  style="width:100%; height:100%; top: 0px; left: 0px;
                overflow:hidden;border:none;" plain="true" buttons="subtabsButtons">
                <div title="选择" class="mini-panel" style="width:100%;height:230px;overflow:hidden;" buttons="">
                    <table width ="100%" height="100%">
                        <tr>
                            <td width ="30%">                    
                                <a class="mini-button" iconCls="icon-add" style="width:100%;" onclick="addRowClSz">新增</a>
                            </td>
                            <td width ="30%">                    
                                <a class="mini-button" iconCls="icon-add" style="width:100%;" onclick="batchRowsClSz">批量新增</a>
                            </td>
                            <td width ="30%">
                                <a class="mini-button" iconCls="icon-remove" style="width:100%;" onclick="removeRowClSz">删除</a>
                            </td>
                        </tr>
                        <tr>
                            <td width ="100%" colspan="3" height="100%">                    
                                <div id="clsz_grid" class="mini-datagrid" style="width:100%;height:100%; margin-top: 4px; " 
                                    url="GetGoodCs" fitColumns="false" oncellbeginedit="OnCellBeginEditCs"
                                    onrowdblclick="OnColorSizeEdit" allowCellEdit="true" allowCellSelect="true" multiSelect="false" showPager ="false">
                                    <div property="columns">
                                        <div type="checkcolumn" width="30" ></div>
                                        <div type="indexcolumn" width="50" headerAlign="center" >序号</div>
                                        <div field="FCsCode" width="230" headerAlign="center" allowSort="true">单品条码
                                            <input property="editor" class="mini-textbox" style="width:100%;"/> 
                                        </div>    
                                        <div field="FColorName" width="120" headerAlign="center" allowSort="true">颜色</div>                                                     
                                        <div field="FSizeName" width="120" headerAlign="center" allowSort="true" >尺码</div>                                    
                                    </div>
                                </div>               
                            </td>
                        </tr>
                    </table>
                </div>
                <div title="编辑" class="mini-panel" style="width:100%;height:365px;" buttons="">
                    <div class="mini-toolbar" style="height:30px;"> 
                        <table style="width:50%;float:left;">
                            <tr>
                                <td style="width:100%;">
                                    <a class="mini-button" name="addcolor" iconCls="icon-new" onclick="colorInfo('new')" plain="true">新增</a>
                                    <a class="mini-button" name="editcolor" iconCls="icon-edit" onclick="colorInfo('edit')" plain="true">修改</a>
                                    <a class="mini-button" name="delcolor" iconCls="icon-close" onclick="delcolor" plain="true">删除</a>
                                </td>
                            </tr>
                        </table>                
                        <table style="width:50%;float:right;">
                            <tr>
                                <td style="width:100%;">
                                    <a class="mini-button" name="addsize" iconCls="icon-new" onclick="sizeInfo('new')" plain="true">新增</a>
                                    <a class="mini-button" name="editsize" iconCls="icon-edit" onclick="sizeInfo('edit')" plain="true">修改</a>
                                    <a class="mini-button" name="delsize" iconCls="icon-close" onclick="delsize" plain="true">删除</a>
                                </td>
                            </tr>
                        </table>                
                    </div>
                    <div style="width:50%;height:300px;float:left;">
                        <div class="mini-fit">
                            <div id="colorgrid" class="mini-datagrid" style="width:100%;height:100%;" pageSize="100"
                                    borderStyle="border:1;" url="GetGoodsColor" showPager="false" idField="FItemID"
                                    allowCellSelect="true" allowCellEdit="true"showColumnsMenu="true"fitColumns="false"  
                                    sortMode="client" multiSelect="false" onrowdblclick="colorInfo('edit')">
                                <div property="columns">
                                    <div type="checkcolumn" width="40">选择</div>
                                    <div header="FItemID" field="FItemID" width="0" visible="false"></div>
                                    <div field="FNumber" name="FNumber" width="100" headeralign="center" allowsort="true">编码</div>
                                    <div field="FName" name="FName" width="190" headeralign="center" allowsort="true">颜色</div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div style="width:50%;height:300px;float:right;">
                        <div class="mini-fit">
                            <div id="sizegrid" class="mini-datagrid" style="width:100%;height:100%;" pageSize="100"
                                    borderStyle="border:1;" url="GetGoodsSize" showPager="false" idField="FItemID"
                                    allowCellSelect="true" allowCellEdit="true"showColumnsMenu="true"fitColumns="false"  
                                    sortMode="client" multiSelect="false" onrowdblclick="sizeInfo('edit')">
                                <div property="columns">
                                    <div type="checkcolumn" width="40">选择</div>
                                    <div header="FItemID" field="FItemID" width="0" visible="false"></div>
                                    <div field="FNumber" name="FNumber" width="100" headeralign="center" allowsort="true">编码</div>
                                    <div field="FName" name="FName" width="190" headeralign="center" allowsort="true">尺码</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

<input name="FClassID" class="mini-hidden" />
<input name="FItemID" class="mini-hidden" />
<input name="FStockQty" class="mini-hidden" />
<input name="FGroupID" class="mini-hidden" />
<input name="FModifyFlag" class="mini-hidden" />
<input name="FDataType" class="mini-hidden" value="2"/>
<input id="ImagFile0" name="ImagFile0" class="mini-hidden" />  
<input id="ImagFile1" name="ImagFile1" class="mini-hidden" />  
<input id="ImagFile2" name="ImagFile2" class="mini-hidden" />  
<input id="ImagFile3" name="ImagFile3" class="mini-hidden" />  
<input id="ImagFile4" name="ImagFile4" class="mini-hidden" />
<input id="ImagFile5" name="ImagFile5" class="mini-hidden" />  
<input id="ImagFile6" name="ImagFile6" class="mini-hidden" />  
<input id="ImagFile7" name="ImagFile7" class="mini-hidden" />  
<input id="ImagFile8" name="ImagFile8" class="mini-hidden" />  
<input id="ImagFile9" name="ImagFile9" class="mini-hidden" />
<input id="ImportFlag" name="ImportFlag" value="0" class="mini-hidden"/>

</form>
<div id="tabsButtons">    
    <div id="ck1" name="ck1"  class="mini-checkbox" style ="margin-right:20px" readOnly="false" value ="true" text="连续新增 "></div>
</div> 
<div id="subtabsButtons">    
    <div>条码生成规则:编码+颜色码+尺寸码</div>
</div> 


<script>
    var comFlag = [{ "id": "0", "text": "否" },
                   { "id": "1", "text": "是" }]

    var comState = [{ "id": "0", "text": "普通商品" },
                    { "id": "1", "text": "称重生鲜商品" },
                    { "id": "2", "text": "计件生鲜商品" }]

    var comPriceType = [{ "id": "0", "text": "停用" },
                       { "id": "1", "text": "在售" }]

    var comPoolAgio = [{ "id": "0", "text": "销售额百分比" },
                       { "id": "1", "text": "毛利额百分比" },
                       { "id": "2", "text": "固定提成金额" }]

    var comPackFlag = [{ "id": "0", "text": "普通商品" },
                       { "id": "1", "text": "组合商品" }]

    var comPointType = [{ "id": "0", "text": "分(固定积分)" },
                       { "id": "1", "text": "%(销售额百分比)" }]

    
    mini.parse();
    var price_grid = mini.get("price_grid");
    var spec_grid = mini.get("Specgrid");
    var loadurl = "";
    var manageurl = "";
    var ImageUrl = "";
    var editor2;

    getUnitName();

    function getUnitName() {
        mini.get("FUnitName").setUrl('../Goods/GetGoodsUnit?mjson=' + parent.window.getSystemAppID());
        if (mini.get("FUnitName").data.length > 0)
            mini.get("FUnitName").setValue(mini.get("FUnitName").data[0].FUnitName);
    }

    //var positionCombo = mini.get("FFreightTemplateID");
    //var url = "/Goods/GetFreightTemplate?mSystemAppID=" + parent.window.getSystemAppID();
    //positionCombo.setUrl(url);
    $(function () {
        KindEditor.ready(function (K) {
            editor2 = K.create('textarea[name="content"]', {
                uploadJson: '../asp.net/upload_json.ashx?dirs=proImage&mSystemAppID=' + parent.window.getSystemAppID() + '&thumb=true' + '&iseDitor=true',
                fileManagerJson: '../asp.net/file_manager_json.ashx?dirs=proImage&mSystemAppID=' + parent.window.getSystemAppID(),
                afterBlur: function () { this.sync(); },
                allowFileManager: true
            });

            $.each($("img"), function (index, e) {
                BindImageClick(K, e);
            });
            ck2Select();
            LoadListcolor();
            LoadListsize();
            mini.getbyName("FMadeDate").setValue(new Date());
        });

        mini.get("FCode").focus();

        $.post("../System/getImgSaveUrl", {}, function (data) {
            ImageUrl = data;
        });
    });

    $(document).ready(function () {
        var index = 0;
        $(".tab-button").eq(index).addClass("active-tab-button");
        $(".tab-button").click(function () {
            // 切换选项卡样式
            $(".tab-button").removeClass("active-tab-button");
            $(this).addClass("active-tab-button");
            // 切换内容显示
            $(".tab-content").removeClass("active");
            $("#" + $(this).data("tab")).addClass("active");
            var sPriceType = $(this).data("tab") // 当前点击的按钮名称
            mini.getbyName("FPriceType").setValue(sPriceType);
            var mFItemID = mini.getbyName("FItemID").getValue();
            mini.getbyName("FNumber").setValue("");
            mini.getbyName("FCode").setValue("");
            if ((sPriceType > 0) && (mFItemID == 0)) GetGoodWeighPlu();
            SetPriceTypeState();
        });
    });

    function onSaveInfo() {
        SaveInfo();
        /*var json = "[{'FItemID':'" + mini.getbyName("FItemID").getValue() + "','FCode':'" + mini.getbyName("FCode").getValue() + "'}]";
        $.post("SaveGoodsCheck", { json: json, mSystemAppID: parent.window.getSystemAppID() }, function (text) {
            if (text != "") {
                var msg = "该条码已经存在，是否要保存？"
                mini.confirm(msg, "提示", function (action) {
                    if (action == "ok") {
                        SaveInfo();
                    }
                });
            }
            else {
                SaveInfo();
            }
        });*/
    };

    //保存资料
    function SaveInfo() {
        var form = new mini.Form("#form1");
        form.validate();
        if (form.isValid() == false) {
            mini.alert("基本资料填写不完整");
            return;
        }
        if (mini.getbyName("FModifyFlag").getValue() == "0") {
            mini.alert("没有修改该商品的权限。");
            return;
        }
        mini.getbyName("FClassID").setValue(mini.getbyName("FClassNumber").getValue());
        if (mini.getbyName("FClassID").getValue() == "") {
            mini.alert("没有选择商品分类");
            return;
        }
        if (mini.getbyName("FName").getValue() == "") {
            mini.alert("商品名称没有输入");
            return;
        }
        if (mini.getbyName("FUnitName").getValue() == "") {
            mini.alert("商品单位没有输入");
            return;
        }
        //if (mini.getbyName("FNumber").getValue() == "") {
        //    mini.alert("商品编码没有输入");
        //    return;
        //}
        if (mini.getbyName("FCode").getValue() == "") {
            mini.alert("商品条码没有输入");
            return;
        }
        //if (mini.getbyName("FStockTotal").getValue() == null) {
        //    mini.alert("商品库存没有输入");
        //    return;
        //}

        //if ((mini.getbyName("FFreshType").getValue() > 0) && (mini.getbyName("FPriceType").getValue() == 0))
        //{
        //    mini.alert("计量方式选择错误，称重商品分类下的商品不能保存为普通商品。");
        //    return;
        //}        
        //if ((mini.getbyName("FFreshType").getValue() == 0) && (mini.getbyName("FPriceType").getValue() > 0)) {
        //    mini.alert("计量方式选择错误，普通商品分类下的商品不能保存为称重商品。");
        //    return;
        //}
        mini.getbyName("SaveInfo").setEnabled(false);
        var data = form.getData(true, false);
        var rows = spec_grid.getData();
        var specJson = mini.encode(rows);
        var clsz_grid = mini.get("clsz_grid");        
        var colorsizerows = clsz_grid.getData();
        var colorsizeJson = mini.encode(colorsizerows);
        var rows_price = price_grid.getChanges();
        var json_price = mini.encode(rows_price);
        var html = $("#content").val().replace("<img src=\"", "<img src=\"" + ImageUrl);
        data.contentHtml = encodeURIComponent(html);
        data.FBrandItemID = mini.getbyName("FBrandItemID").getValue();
        var json = mini.encode(data);
        $.post("SaveGoodsInfo", { json: json, specjson: specJson, colorjson: colorsizeJson, pricejson: json_price, mSystemAppID: parent.window.getSystemAppID() }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 }, function () {
                    mini.alert("保存完成");
                });
                NewInfo();
                if (mini.getbyName("ck1").getChecked() == false)
                    setTimeout(CloseWindow, 1000);
            }
            else {
                mini.alert("异常：" + ret.error);
            }

            mini.getbyName("FCode").enable();
            mini.getbyName("FName").enable();
            mini.getbyName("FSpec").enable();
            mini.getbyName("FUnitName").enable();
            mini.getbyName("FSpelling").enable();
            mini.getbyName("FCode").focus();

            mini.getbyName("SaveInfo").setEnabled(true);
        });
    }

    function SetDiscount(discount) {
        mini.getbyName("FLowestDis").setValue(discount);
    }

    function addSpecInfo() {
        var r = spec_grid.getData().length + 1;
        var unitName = mini.getbyName("FUnitName").getValue();
        var costPrice = mini.getbyName("FPurPrice").getValue();
        var posPrice = mini.getbyName("FPosPrice").getValue();
        var vipPrice = mini.getbyName("FVipPrice").getValue();
        var selPrice = mini.getbyName("FSelPrice").getValue();
        var sRmoPrice = mini.getbyName("FRmoPrice").getValue();
        var FMallPrice = mini.getbyName("FMallPrice").getValue();
        var sMallFlag = mini.getbyName("FMallFlag").getValue();
        var sHotSale = mini.getbyName("FHotSale").getValue();
        var sRequireFlag = mini.getbyName("FRequireFlag").getValue();
        var sMallUnit = mini.getbyName("FMallUnit").getValue();
        var sMallConvert = mini.getbyName("FMallConvert").getValue();
        var row = {
            FItemID: 0, FSpec: '', FUnitName: unitName, FPurPrice: costPrice, FPosPrice: posPrice, FRmoPrice: sRmoPrice,
            FSelPrice: selPrice, FVipPrice: vipPrice, FLowestDis: 0, FMallPrice: FMallPrice, FConvert: 1, FMallFlag: sMallFlag,
            FRequireFlag: sRequireFlag, FMallUnit: sMallUnit, FMallConvert: sMallConvert, FHotSale: sHotSale
        };
        spec_grid.addRow(row, r);

        spec_grid.cancelEdit();
        spec_grid.beginEditRow(r);
    }

    function ImageFilePath(url) {
        var result = "";
        $.ajax({
            url: "/GetItem/GetImageFilePath",
            data: { Url: url },
            type: "post",
            async: false,
            success: function (data) {
                result = data;
            },
            failure: function () {
                result = "";
            },
            error: function (jqXHR, textStatus, errorThrown) {
                return "";
            }
        });
        return result;
    }

    function ClassOnValuechanged(FreshType) {        
        mini.getbyName("FPriceType").setValue(FreshType);
    }

    function SetPriceTypeBtn(index) {
        $(document).ready(function () {
            //var index = 1;
            $(".tab-button").removeClass("active-tab-button");
            $(".tab-button").eq(index).addClass("active-tab-button");
        });
        //alert(index);
    }

    function SetInfoData(data) {
        $(".mini-tabs-body").css("overflow", "hidden");
        if (data.action == "new") {
            //跨页面传递的数据对象，克隆后才可以安全使用
            mini.getbyName("FFreshType").setValue(data.FFreshType);
            setGoodsScale(data.FFreshType);
            mini.getbyName("FItemID").setValue('0');
            mini.getbyName("FClassNumber").setValue(data.FClassID);
            mini.getbyName("FClassNumber").setText(data.FClassNumber);
            mini.getbyName("FGoodsClassName").setValue(data.FClassName);
            mini.getbyName("FPriceType").setValue(data.FFreshType);
            mini.getbyName("FSupplyItemID").setValue(0);
            mini.getbyName("FSupplyItemID").setText("0");
            mini.getbyName("FSupplyName").setValue("默认供应商");
            mini.getbyName("FStockQty").setValue(0);
            mini.getbyName("ck1").setValue(true);
            SetPriceTypeBtn(data.FFreshType);
            SetPriceTypeState();
            NewInfo();
        }
        else {
            mini.mask({el: document.body,cls: 'mini-mask-loading',html: '加载中...'});
            mini.getbyName("FItemID").setValue(data.FItemID);
            $("#QCodeIFrame").attr("src", "../Goods/GetQCode?mSystemAppID=" + parent.window.getSystemAppID() + "&GoodID=" + data.FItemID);
            $.post("GetGood", { json: "[{'FItemID':'" + data.FItemID + "','mSystemAppID':'" + parent.window.getSystemAppID() + "'}]" }, function (data) {
                mini.unmask(document.body);
                var form = new mini.Form("form1");
                var mdata = mini.decode(data);
                if (mdata.data[0].FDeleted == -1) {
                    mini.alert("商品已经被删除");
                    CloseWindow();
                    return;
                }
                form.setData(mdata.data[0]);
                mini.getbyName("FClassNumber").setValue(mdata.data[0].FClassID);
                mini.getbyName("FClassNumber").setText(mdata.data[0].FClassNumber);                
                mini.getbyName("FBrandItemID").setValue(mdata.data[0].FBrandID);
                mini.getbyName("FBrandItemID").setText(mdata.data[0].FBrandItemID);
                mini.getbyName("FPriceBookID").setValue(mdata.data[0].FPriceBookID);
                mini.getbyName("FPriceBookID").setText(mdata.data[0].FBookNumber);
                mini.getbyName("FPriceBookName").setValue(mdata.data[0].FBookName);
                mini.getbyName("FPackFlag").setValue(mdata.data[0].FPackFlag);
                mini.getbyName("FMallFlag").setValue(mdata.data[0].FMallFlag ? 1 : 0);
                mini.getbyName("FHotSale").setValue(mdata.data[0].FHotSale ? 1 : 0);
                mini.getbyName("FRequireFlag").setValue(mdata.data[0].FRequireFlag ? 1 : 0);
                mini.getbyName("FSupplyItemID").setValue(mdata.data[0].FSupplierID);
                mini.getbyName("FSupplyItemID").setText(mdata.data[0].FSuppNumber);
                mini.getbyName("FSupplyName").setValue(mdata.data[0].FSuppName);
                mini.getbyName("FFreshType").setValue(mdata.data[0].FFreshType);
                mini.getbyName("FStockQty").setValue(mdata.data[0].FStockTotal);
                mini.getbyName("FWeighPlu").setValue(mdata.data[0].FWeighPlu);
                setGoodsScale(mdata.data[0].FFreshType);
                price_grid.setData(mdata.dataprice);
                if (mdata.data[0].FPackBillFlag == 1) {
                    mini.getbyName("FPackFlag").setEnabled(false);
                }
                getDefaultBrand();
                if (mdata.data[0].FRebateID == null)
                    mini.get("FRebateID").setValue(0);
                else
                    mini.get("FRebateID").setValue(mdata.data[0].FRebateID);
                if (mdata.data[0].FPointType == null)
                    mini.get("FPointType").setValue(0);
                else
                    mini.get("FPointType").setValue(mdata.data[0].FPointType);
                var htmlstr = decodeURIComponent(mdata.data[0].FContent);
                editor2.insertHtml(htmlstr);
                if (mdata.data[0].FProImage != "" && mdata.data[0].FProImage != null) {
                    setImage(mdata.data[0].FProImage);
                }
                mini.getbyName("ck1").setValue(true);                
                if (mdata.data[0].FGroupID > 0) {
                    getGroupCS(mdata.data[0].FColorID, mdata.data[0].FSizeID, mdata.data[0].FItemID);
                }
                else if (mdata.data[0].FItemFlag == 1) {                    
                    spec_grid.load({ json: mdata.data[0].FItemID, mSystemAppID: parent.window.getSystemAppID() });
                }

                if (mdata.data[0].FImportFlag == 1) {
                    $(".rebateRow").show();
                    mini.getbyName("ImportFlag").setValue("1");
                }
                else
                    mini.getbyName("ImportFlag").setValue("0");
                mini.getbyName("FStockLimitFlag").setValue(mdata.data[0].FStockLimitFlag);
                mini.getbyName("FSpellingType").setValue(mdata.data[0].FSpellingType);
                SpellingCheck();
                if (mdata.data[0].isParent == 1)
                    mini.getbyName("FPriceBookID").setEnabled(true);
                else
                    mini.getbyName("FPriceBookID").setEnabled(false);
                ComputeGPM();
                SetPriceTypeBtn(mdata.data[0].FPriceType);
                SetPriceTypeState();
            });
        }

    }

    function getGoodsPrice() {
        var sSystemAppID = parent.window.getSystemAppID();
        var json = "[{";
        json = json + "'FSystemAppID':" + "'" + sSystemAppID + "',";
        json = json + "'mBookPriceID':" + "'" + classid + "',";
        json = json + "'mNumber':" + "'" + mini.getbyName("FSearchKeyS").getValue() + "',";
        json = json + "'mGoodsID':" + "'0',";
        json = json + "'mDatatype':" + "'" + mdatatype + "'";
        json = json + "}]";
        grid.load({ mydata: json });
    }

    function onPriceTypeChanged() {
        var mpriceType = mini.get("FPriceType").getValue();
        if (mpriceType > 0) {
            mini.getbyName("FNumber").setEnabled(false);
        } else {
            mini.getbyName("FNumber").setEnabled(true);
        }
    }

    function SetPriceTypeState() {
        var mpriceType = mini.get("FPriceType").getValue();
        if (mpriceType > 0) {
            mini.getbyName("FWeighPlu").setEnabled(true);
            mini.getbyName("FNumber").setEnabled(false);
        } else {
            mini.getbyName("FWeighPlu").setEnabled(false);
            mini.getbyName("FNumber").setEnabled(true);
        }
    }

    function setGoodsScale(mFreshType)
    {
        if (mFreshType > 0) {
            //mini.getbyName("FClassNumber").setEnabled(false);
            //mini.getbyName("FNumber").setEnabled(false);
        }
    }

    function setImage(FProImage) {
        var ImgFile = FProImage.split("$");
        if (ImgFile.length > 0) {
            $.each(ImgFile, function (key, item) {
                if (item != "") {
                    item = ImageFilePath(item);
                    $("#Image" + key).attr("src", item);
                    mini.getbyName("ImagFile" + key).setValue(item);
                }
            });
        }
        for (var i = 0; i < 10; i++) {
            if ("~/Content/Images/NoImage.jpg" != mini.getbyName("ImagFile" + i).getValue())
                mini.getbyName("ImagFile" + i).setValue($("#Image" + i).attr("src"));
        }
    }

    function FindGood() {
        if (mini.getbyName("FItemID").getValue() > 0) return;
        var code = mini.getbyName("FCode").getValue();
        //alert(code.length);
        if (code.length < 13) return;
        $.post("GetImportGoodInfo", { json: "[{'FCode':'" + code + "','mSystemAppID':'" + parent.window.getSystemAppID() + "'}]" }, function (data) {
            var form = new mini.Form("form1");
            var mdata = mini.decode(data);
            var checkadd = mini.getbyName("ck1").getChecked();
            if (mdata.status == "1") {
                mini.alert("该条码已存在，建议不要重复添加。", "提示：",
                    function (action) {
                        mini.getbyName("FName").focus();
                });
            }
            else {
                if (mdata.data != undefined && mdata.data.length > 0) {
                    var row = mdata.data[0];
                    mini.getbyName("FName").setValue(row.FName);
                    mini.getbyName("FSpec").setValue(row.FSpec);
                    mini.getbyName("FPosPrice").setValue(row.FPosPrice);
                    mini.getbyName("FPurPrice").setValue(row.FPurPrice);
                    mini.getbyName("FStockTotal").setValue(0);

                    if (mdata.data[0].FProImage != "" && mdata.data[0].FProImage != null) {
                        var ImgFile = mdata.data[0].FProImage.split("$");
                        if (ImgFile.length > 0) {
                            $.each(ImgFile, function (key, item) {
                                if (item != "") {
                                    item = ImageFilePath(item);
                                    $("#Image" + key).attr("src", item);
                                    mini.getbyName("ImagFile" + key).setValue(item);
                                }
                            });
                        }
                    }
                    for (var i = 1; i < mdata.data.length; i++) {
                        var row = {
                            "FCode": mdata.data[i].FCode, "FSpec": mdata.data[i].FSpec, "FUnitName": mdata.data[i].FUnitName,
                            "FConvert": mdata.data[i].FConvert, "FPurPrice": 0, "FPosPrice": 0, "FSelPrice": 0, "FVipPrice": 0, "FLowestDis": 0,
                            "FMallPrice": 0, "FRmoPrice": 0
                        }
                        spec_grid.addRow(row, 0);
                    }
                    for (var i = 0; i < 10; i++) {
                        if ("~/Content/Images/NoImage.jpg" != mini.getbyName("ImagFile" + i).getValue())
                            mini.getbyName("ImagFile" + i).setValue($("#Image" + i).attr("src"));
                    }
                    var htmlstr = decodeURIComponent(mdata.data[0].FContent);
                    editor2.insertHtml(htmlstr);
                    $("#rebateRow").hide();                    
                    mini.getbyName("FPosPrice").focus();
                    mini.getbyName("FPosPrice").setValue("");
                }
            }            
        });
    }

    function GetGoodWeighPlu() {
        var goodplu = mini.getbyName("FWeighPlu").getValue();
        if (goodplu.length < 1) return;
        var mjson = "[{'FWeighPlu':'" + goodplu
            + "','FGoodsID':'" + mini.getbyName("FItemID").getValue()
            + "','mSystemAppID':'" + parent.window.getSystemAppID()
            + "'}]"
        $.post("GetGoodWeighPlu", { json: mjson }, function (data) {
            var mdata = mini.decode(data);            
            if (mdata.status == "1") {
                mini.alert("该秤重Plu已存在。", "提示：",
                    function (action) {
                        mini.getbyName("FWeighPlu").setValue(mdata.goodsplu);
                        if (mini.getbyName("FCode").getValue() == "")
                        {
                            mini.getbyName("FCode").setValue(mdata.barcode);
                            mini.getbyName("FName").focus();
                        }
                    });
            }
            else {
                mini.getbyName("FWeighPlu").setValue(mdata.goodsplu);
                mini.getbyName("FNumber").setValue(mdata.barcode);
                if (mini.getbyName("FCode").getValue() == "") {
                    mini.getbyName("FCode").setValue(mdata.barcode);                    
                    mini.getbyName("FName").focus();
                }
            }
        });
    }

    function NewInfo() {
        mini.getbyName("FItemID").setValue("0");
        mini.getbyName("FName").setValue("");
        mini.getbyName("FPurPrice").setValue("");
        mini.getbyName("FSelPrice").setValue("");
        mini.getbyName("FPosPrice").setValue("");
        mini.getbyName("FVipPrice").setValue("");
        mini.getbyName("FRmoPrice").setValue("");
        mini.getbyName("FMallPrice").setValue("");
        mini.getbyName("FPoint").setValue("");
        mini.getbyName("FLowestDis").setValue("0");
        mini.getbyName("FSpec").setValue("");
        mini.getbyName("FCode").setValue("");
        mini.getbyName("FSpelling").setValue("");
        mini.getbyName("FModifyFlag").setValue("1");
        mini.getbyName("FPackFlag").setEnabled(true);
        mini.getbyName("FStockTotal").setValue("0");
        mini.getbyName("FStockQty").setValue("0");
        mini.getbyName("FWeighPlu").setValue("1");
        var date = new Date();
        var str = (date.getFullYear()) + "-" + (date.getMonth() + 1) + "-" + date.getDate();

        var mClassID = mini.getbyName("FClassNumber").getValue();
        //var mjson = "{";
        //mjson = mjson + "'FClassID':" + "'" + mClassID + "',";
        //mjson = mjson + "'FreshType':" + "'" + mini.getbyName("FFreshType").getValue() + "'";
        //mjson = mjson + "}";
        //$.post('NewGoodsInfo', { json: mjson, mSystemAppID: parent.window.getSystemAppID() }, function (data) {
        //    var mdata = mini.decode(data);
        //    if ((mdata.class.length > 0) && (mClassID == 0)) {
        //        mini.getbyName("FClassNumber").setValue(mdata.class[0].FItemID);
        //        mini.getbyName("FClassNumber").setText(mdata.class[0].FNumber);
        //        mini.getbyName("FGoodsClassName").setValue(mdata.class[0].FName);
        //    }

        //    mini.getbyName("FNumber").setValue(mdata.number);
        //    if (mini.getbyName("FFreshType").getValue() == 1)
        //        mini.getbyName("FCode").setValue(mdata.number);
        //});

        if (mini.getbyName("FFreshType").getValue() > 0) GetGoodWeighPlu();
        getDefaultBrand();
        price_grid.setData(null);
        spec_grid.setData(null);
        if (mini.getbyName("FPriceBookID").getValue() == "") {
            var jsonstr = '[{"mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
            $.post("../Stock/DefaultPB", { json: jsonstr }, function (data) {
                var mdata = mini.decode(data);
                if (mdata.data.length > 0) {
                    mini.getbyName("FPriceBookID").setValue(mdata.data[0].FItemID);
                    mini.getbyName("FPriceBookID").setText(mdata.data[0].FNumber);
                    mini.getbyName("FPriceBookName").setValue(mdata.data[0].FName);
                }
            });
        }
        //$.post("../System/GetCorpDefault", { mSystemAppID: parent.window.getSystemAppID() }, function (data) {
        //    var mdata = mini.decode(data);
        //    if (mdata.data.length > 0) {
        //        if (mdata.data[0].FBillType == 1)
        //            $(".rebateRow").show();
        //    }
        //});

        //缺省价格方案
        $.post("DefaultPriceBook", { json: '[{"mSystemAppID":"' + parent.window.getSystemAppID() + '"}]' }, function (data) {
            var mdata = mini.decode(data);
            if (mdata.data.length > 0) {
                mini.getbyName("FPriceBookID").setText(mdata.data[0].FNumber);
                mini.getbyName("FPriceBookID").setValue(mdata.data[0].FItemID);
                mini.getbyName("FPriceBookName").setValue(mdata.data[0].FName);
            }
        });
    }

    function getDefaultBrand()
    {
        if (mini.getbyName("FBrandItemID").getValue() == "") {
            $.post("../Brand/DefaultBrand", { mSystemAppID: parent.window.getSystemAppID() }, function (data) {
                var mdata = mini.decode(data);
                if (mdata.data.length > 0) {
                    mini.getbyName("FBrandItemID").setValue(mdata.data[0].FItemID);
                    mini.getbyName("FBrandItemID").setText(mdata.data[0].FNumber);
                    mini.getbyName("FBrandName").setValue(mdata.data[0].FName);
                }
            });
        }
    }

    function GCode(s) {
        var REGX_HTML_ENCODE = /"|&|'|<|>|[\x00-\x20]|[\x7F-\xFF]|[\u0100-\u2700]/g
        return (typeof s != "string") ? s :
            s.replace(REGX_HTML_ENCODE,
                      function ($0) {
                          var c = $0.charCodeAt(0), r = ["&#"];
                          c = (c == 0x20) ? 0xA0 : c;
                          r.push(c); r.push(";");
                          return r.join("");
                      });
    };

    function removeSpecInfo() {
        var row = spec_grid.getSelected();
        var FSystemAppID = parent.window.getSystemAppID();
        if (row) {
            mini.confirm("确定要删除选中的记录吗？", "提示",
                function (action) {
                    if (action == "ok") {
                        $.post("RemoveGoodsInfo", { json: '[{"FItemID":' + row.FItemID + '}]', mSystemAppID: FSystemAppID }, function (data) {
                            var ret = mini.decode(data);
                            if (ret.status == 1) {
                                spec_grid.reload();
                            }
                            else {
                                spec_grid.reload();
                            }
                        });
                    }
                });
        } else {
            mini.alert("请选中一条记录");
        }
    }

    function BindImageClick(K, e) {        
        K('#' + $(e).attr("id")).click(function (K) {
            var imgIndex = $(this).attr("id").replace("Image", "");
            var url = $(this).attr('src');
            if (url.toLowerCase() != "/content/images/noimage.jpg") {
                var cfg = confirm("你确定要删除当前图片信息？");
                if (!cfg) {
                    return;
                }
                else {
                    $(this).attr('src', "/content/Images/NoImage.jpg");
                    mini.getbyName("ImagFile" + imgIndex).setValue("");
                    return;
                }
            }
            editor2.loadPlugin('image', function () {
                editor2.plugin.imageDialog({
                    //imageUrl: "",
                    clickFn: function (url, title, width, height, border, align) {
                        $("#ImagFile" + imgIndex).val(url);
                        var path = ImageFilePath(url);
                        $("#Image" + imgIndex).attr('src', path);
                        editor2.hideDialog();
                    }
                });
            });
        });
    }


    function changeTabs(sender, tab) {
        if (sender.name == "DPic") {
            loadurl = editor2.uploadJson = '../asp.net/upload_json.ashx?dirs=proImage&mSystemAppID=' + parent.window.getSystemAppID() + '&thumb=true' + '&iseDitor=false';
            manageurl = editor2.fileManagerJson = '../asp.net/file_manager_json.ashx?dirs=proImage&mSystemAppID=' + parent.window.getSystemAppID();
        }
        else if (sender.name == "DHtml") {
            loadurl = editor2.uploadJson = '../asp.net/upload_json.ashx?dirs=content&mSystemAppID=' + parent.window.getSystemAppID() + '&thumb=false' + '&iseDitor=true';
            manageurl = editor2.fileManagerJson = '../asp.net/file_manager_json.ashx?dirs=content&mSystemAppID=' + parent.window.getSystemAppID();
        }
    }

    function syncImage() {
        mini.confirm("确定要按条码图片文件同步所有商品图片吗？", "提示",
        function (action) {
            if (action == "ok") {
                setSyncImage();
            }
        }
   );
    }

    function setSyncImage() {
        mini.mask({
            el: document.body,
            cls: 'mini-mask-loading',
            html: '加载中...'
        });
        var FItemID = mini.getbyName("FItemID").getValue();
        var jsonstr = '[{"FItemID":"' + FItemID + '","mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
        $.post("SyncImage", { json: jsonstr }, function (data) {
            mini.unmask(document.body);
            var ret = mini.decode(data);
            if (ret.status == 1) {
                mini.showTips({ content: "获取成功", state: "success", x: "center", y: "top", timeout: 3000 });
                var imgstr = mini.decode(ret.msg);
                setImage(imgstr.data[0].FProImage);
            }
            else
                mini.showTips({ content: "获取失败", state: "danger", x: "center", y: "top", timeout: 3000 });
        });
    }

    function syncAllImage() {
        mini.mask({
            el: document.body,
            cls: 'mini-mask-loading',
            html: '加载中...'
        });
        var FItemID = mini.getbyName("FItemID").getValue();
        var jsonstr = '[{"FItemID":"' + FItemID + '","mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
        $.post("SyncAllImage", { json: jsonstr }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                mini.showTips({ content: "获取成功", state: "success", x: "center", y: "top", timeout: 3000 });
                var imgstr = mini.decode(ret.msg);
                setImage(imgstr.data[0].FProImage);
            }
            else
                mini.showTips({ content: "获取失败", state: "danger", x: "center", y: "top", timeout: 3000 });
            mini.unmask(document.body);
        });
    }

    function setkeyPress() {
        LoadListData();
    }

    //新增
    var colorgrid = mini.get("colorgrid");
    var sizegrid = mini.get("sizegrid");
    var st;

    function ck2Select() {
        var tabs = mini.get("tabs1");
        var tabcolor = tabs.getTab("colorSpec");
        var spec = tabs.getTab("Spec");
        if (mini.getbyName("ck2").checked == true) {
            tabs.updateTab(spec, { visible: false });
            tabs.updateTab(tabcolor, { visible: true });
            spec_grid.clearRows();
        }
        else {
            tabs.updateTab(spec, { visible: true });
            tabs.updateTab(tabcolor, { visible: false });
        }
    }

    function limitCheck() {
        if (mini.getbyName("FStockLimitFlag").checked == true) {
            mini.getbyName("FHightLimit").setEnabled(true);
            mini.getbyName("FLowLimit").setEnabled(true);
        }
        else {
            mini.getbyName("FHightLimit").setEnabled(false);
            mini.getbyName("FLowLimit").setEnabled(false);
        }
    }

    function SpellingCheck() {
        if (mini.getbyName("FSpellingType").checked == true) {
            mini.getbyName("FSpelling").setEnabled(true);
        }
        else {
            mini.getbyName("FSpelling").setEnabled(false);
        }
    }
    

    function LoadListcolor() {
        var sSystemAppID = parent.window.getSystemAppID();
        var json = "[{";
        json = json + "'mSystemAppID':" + "'" + sSystemAppID + "'";
        json = json + "}]";
        colorgrid.load({ mydata: json });
    }

    function LoadListsize() {
        var sSystemAppID = parent.window.getSystemAppID();
        var json = "[{";
        json = json + "'mSystemAppID':" + "'" + sSystemAppID + "'";
        json = json + "}]";
        sizegrid.load({ mydata: json });
    }

    function LoadListcolorsize(groupId) {
        colorszgrid = mini.get("clsz_grid");
        var sSystemAppID = parent.window.getSystemAppID();
        var jsonstr = "[{";
        jsonstr = jsonstr + "'mSystemAppID':" + "'" + sSystemAppID + "',";
        jsonstr = jsonstr + "'mGroupID':" + "'" + groupId + "'";
        jsonstr = jsonstr + "}]";
        colorszgrid.load({ json: jsonstr });
    }

    function colorInfo(act) {
        var FID = "0";
        if (act == "edit")
            FID = colorgrid.getSelected().FItemID;
        mini.open({
            url: "/Goods/ColorInfo",
            title: "颜色", width: 500, height: 280,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: act, FItemID: FID };
                iframe.contentWindow.SetInfoData(data);
            },
            ondestroy: function (action) {
                colorgrid.reload();
            }
        });
    }

    function delcolor() {
        var colorrows = colorgrid.getSelecteds();
        if (colorrows.length == 0) return;
        var colorJson = mini.encode(colorrows);
        var sSystemAppID = parent.window.getSystemAppID();
        $.post("/Goods/deleteInfo", { json: colorJson, mSystemAppID: sSystemAppID, Type: "color" }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 }, function () { });
                LoadListcolor();
            }
            else {
                mini.showTips({ content: ret.error, state: "danger", x: "center", y: "top", timeout: 3000 }, function () { });
            }
        });
    }

    function delsize() {
        var sizerows = sizegrid.getSelecteds();
        if (sizerows.length == 0) return;
        var sizeJson = mini.encode(sizerows);
        var sSystemAppID = parent.window.getSystemAppID();
        $.post("/Goods/deleteInfo", { json: sizeJson, mSystemAppID: sSystemAppID, Type: "size" }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 }, function () { });
                LoadListsize();
            }
            else {
                mini.showTips({ content: ret.error, state: "danger", x: "center", y: "top", timeout: 3000 }, function () { });
            }
        });
    }

    function sizeInfo(act) {
        var FID = "0";
        if (act == "edit")
            FID = sizegrid.getSelected().FItemID;
        mini.open({
            url: "/Goods/SizeInfo",
            title: "尺码", width: 500, height: 280,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: act, FItemID: FID };
                iframe.contentWindow.SetInfoData(data);
            },
            ondestroy: function (action) {
                sizegrid.reload();
            }
        });
    }

    function removeInfo(type) {
        var row;
        if (type == "color")
            row = colorgrid.getSelected();
        else if (type == "size")
            row = sizegrid.getSelected();
        var FSystemAppID = parent.window.getSystemAppID();
        if (row) {
            mini.confirm("确定要删除选中的记录吗？", "提示",
                function (action) {
                    if (action == "ok") {
                        var json = "{'FItemID':'" + row.FItemID + "'}";
                        $.post("deleteInfo", { json: json, mSystemAppID: FSystemAppID, Type: type }, function (data) {
                            var ret = mini.decode(data);
                            if (ret.status == 1) {
                                grid.reload();
                            }
                            else {
                                mini.alert("异常:" + ret.error);
                            }
                        });
                    }
                }
            );
        }
    }

    function getGroupCS(ColorID, SizeID, GoodID) {
        //st = setTimeout(detection, 1500, ColorID, SizeID);
        LoadListcolorsize(GoodID);
        mini.get("ck2").setValue(true);
        ck2Select();
        setColortab(false);
    }

    function setColortab(b) {
        //colorgrid_Enabled(false);
        //sizegrid_Enabled(false);
        mini.getbyName("ck2").setEnabled(b);
    }

    function colorgrid_Enabled(b) {
        colorgrid.on("beforeselect", function (e) {
            var rows = colorgrid.getSelecteds();
            colorgrid.deselects(rows);
        })
    }

    function sizegrid_Enabled(b) {
        sizegrid.on("beforeselect", function (e) {
            var rows = sizegrid.getSelecteds();
            sizegrid.deselects(rows);
        })
    }

    function detection(ColorID, SizeID) {
        var color_rows = colorgrid.getData();
        for (var i = 0; i < color_rows.length; i++) {
            if (color_rows[i].FItemID == ColorID)
                colorgrid.select(color_rows[i]);
        }
        var size_rows = sizegrid.getData();
        for (var j = 0; j < size_rows.length; j++) {
            if (size_rows[j].FItemID == SizeID) {
                sizegrid.select(size_rows[j]);
            }
        }
        clearTimeout(st);
    }

    var CLSzColorID = 0;
    var CLSzSizeID = 0;
    var CLSZcolorname = '';
    var CLSZcolornumber = '';
    var CLSZsizename = '';
    var CLSZsizenumber = '';
    function addRowClSz() {
        mini.open({
            url: "../GetItem/Index",
            title: "颜色选择", width: 730, height: 460,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "new", sTbName: "ColorInfo", sSearchKey: '' };
                iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
                if (action == "close") return;
                if (action.length > 0 && action.sender == undefined) {
                    CLSzColorID = action[0].FItemID;
                    CLSZcolornumber = action[0].FNumber;
                    CLSZcolorname = action[0].FName;
                    addCLSzSize();
                }
            }
        });
    }

    function addCLSzSize() {
        mini.open({
            url: "../GetItem/Index",
            title: "尺寸选择", width: 730, height: 460,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "new", sTbName: "SzieInfo", sSearchKey: '' };
                iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
                if (action == "close") return;
                if (action.length > 0 && action.sender == undefined) {
                    CLSzSizeID = action[0].FItemID;
                    CLSZsizenumber = action[0].FNumber;
                    CLSZsizename = action[0].FName;
                    var clsz_grid = mini.get("clsz_grid");
                    var mFItemID = "";
                    for (var j = 0, m = clsz_grid.getData().length; j < m; j++) {
                        var rs = clsz_grid.getRow(j);
                        if ((CLSzColorID == rs.FColorID) && (CLSzSizeID == rs.FSizeID)) {
                            mFItemID = rs.FGoodsID;
                        }
                    }
                    if (mFItemID == "") {
                        var code = mini.getbyName("FNumber").getValue() + CLSZcolornumber + CLSZsizenumber
                        var newRow = {
                            FGoodsID: "0", FCsGroupID: "0", FCsCode: code, FSizeID: CLSzSizeID, FSizeNumber: CLSZsizenumber,
                            FSizeName: CLSZsizename, FColorID: CLSzColorID, FColorNumber: CLSZcolornumber, FColorName: CLSZcolorname
                        };
                        clsz_grid.addRow(newRow, clsz_grid.getData().length);
                    }

                }
            }
        });
    }

    function batchRowsClSz() {
        mini.open({
            url: "../Goods/BatchAddCs",
            title: "批量增加颜色尺码", width: 700, height: 480,
            onload: function () {
            },
            ondestroy: function (action) {
                if (action != undefined && action.sender != undefined && action.sender.iconCls == "icon-close") {
                    return;
                }
                if (action && action != "close") {
                    if (validCLSz(action.color, action.size) == false) {
                        mini.alert("所选颜色尺码已经存在，不能添加重复的数据");
                        return;
                    }
                    else {
                        batchaddCLSz(action.color, action.size);
                    }
                }
            }
        });
    }

    //批量增加前检测
    function validCLSz(colordata, sizedata, mColorID, mSizeID) {
        var clsz_grid = mini.get("clsz_grid");
        for (var c = 0; c < colordata.length; c++) {
            for (var s = 0; s < sizedata.length; s++) {
                for (var j = 0, m = clsz_grid.getData().length; j < m; j++) {
                    var rs = clsz_grid.getRow(j);
                    if (colordata[c].FItemID == rs.FColorID && sizedata[s].FItemID == rs.FSizeID) {
                        return false;
                    }
                }
            }
        }
        return true;
    }

    //批量增加
    function batchaddCLSz(colordata, sizedata) {
        debugger;
        var clsz_grid = mini.get("clsz_grid");
        for (var c = 0; c < colordata.length; c++) {
            for (var s = 0; s < sizedata.length; s++) {
                var code = mini.getbyName("FNumber").getValue() + colordata[c].FNumber + sizedata[s].FNumber;
                var newRow = {
                    FGoodsID: "0", FCsGroupID: "0", FCsCode: code, FSizeID: sizedata[s].FItemID, FSizeNumber: sizedata[s].FNumber,
                    FSizeName: sizedata[s].FName, FColorID: colordata[c].FItemID, FColorNumber: colordata[c].FNumber, FColorName: colordata[c].FName
                };
                clsz_grid.addRow(newRow, clsz_grid.getData().length);
            }
        }
    }

    function removeRowClSz() {
        mini.confirm("确定要删除选中颜色尺码?", "提示", function (action) {
            if (action == "ok") {
                var clsz_grid = mini.get("clsz_grid");
                var mFItemID = mini.getbyName("FItemID").getValue();
                var row = clsz_grid.getSelected();
                if ((row.FGoodsID == mFItemID) && (mFItemID > 0)) {
                    mini.alert("主商品颜色尺码不能删除!");
                }
                else {
                    var jsonstr = '[{"mSystemAppID":"' + parent.window.getSystemAppID() + '","FGoodsID":' + row.FGoodsID
                        + ',"FColorID":' + row.FColorID + ',"FSizeID":' + row.FSizeID + ',"FGroupID":' + row.FCsGroupID + '}]';
                    clsz_grid.removeRow(row, true);
                    $.post("delcolorsize", { json: jsonstr }, function (data) {
                        var Data = mini.decode(data);
                        if (Data.status == 1) {
                            mini.alert("删除成功");
                        }
                        else if (Data.msg != "") {
                            mini.alert(Data.msg);
                        }
                    });
                }
            }
        });
    }


    function getGoodsImgFrom() {
        mini.open({
            url: "../GetItem/GetGoodsImg",
            title: "图片选择", width: 600, height: 460,
            onload: function () {},
            ondestroy: function (action) {
                if (action.length > 0) {
                    setImage(action[0].FGoodsImg + "$");
                }
            }
        });
    }

    function OnCellBeginEditCs(e) {
        var mFItemID = mini.getbyName("FItemID").getValue();
        var row = e.record;
        if ((row.FGoodsID == mFItemID) && (row.FGoodsID != "0") && (e.field == "FCsCode")) {
            e.cancel = true;
        }
    }

    function OnColorSizeEdit(e) {
        var clsz_grid = mini.get("clsz_grid");
        var row = clsz_grid.getSelected();
        if (row) {
            var rowid = clsz_grid.indexOf(row);
            mini.open({
                url: "../Goods/ProductEditCs",
                title: "颜色尺码资料", width: 480, height: 340,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    iframe.contentWindow.SetData(row);
                },
                ondestroy: function (action) {
                    if (action && action != "close" && action.FCsCode!=undefined) {
                        var mColorID = action.FColorID;
                        var mSizeID = action.FSizeID;
                        var mCsCode = action.FCsCode;

                        var mFItemID = "";
                        for (var j = 0, m = clsz_grid.getData().length; j < m; j++) {
                            var rs = clsz_grid.getRow(j);
                            if ((mColorID == rs.FColorID) && (mSizeID == rs.FSizeID) && (rowid != j)) {
                                mFItemID = rs.FGoodsID;
                                mini.alert("该颜色尺码已经存在，不能添加重复的数据");
                            }
                        }
                        if (mFItemID == "") {
                            var editRow = {
                                FCsCode: action.FCsCode, FSizeID: mSizeID, FSizeName: action.FSizeName, FSizeNumber: action.FSizeNumber,
                                FColorID: mColorID, FColorName: action.FColorName, FColorNumber: action.FColorNumber
                            };
                            clsz_grid.updateRow(row, editRow);
                        }
                    }
                }
            });

        } else {
            mini.alert("请选中一条记录");
        }
    }

    function ComputeGPM() {
        var posprice = mini.getbyName("FPosPrice").getValue();
        var purprice = mini.getbyName("FPurPrice").getValue();
        var gpm = (posprice - purprice) / posprice;
        mini.getbyName("FGPM").setValue(gpm);
    }

    function ComputePrice() {
        var gpm = mini.getbyName("FGPM").getValue();
        var purprice = mini.getbyName("FPurPrice").getValue();
        if (gpm != 1) {
            var posprice = purprice / (1 - gpm);
            //mini.getbyName("FPosPrice").setValue(posprice);
        }
    }
</script>

